package com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.rxRegistration.entity.req.RxRegistrationPlanSettingReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.entity.req.RxRegistrationExamineBlackListBatchAddReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.entity.req.RxRegistrationExamineBlackListReq;
import com.xyht.sca_s.student_manage_system.modules.rxRegistrationExamine.service.RxRegistrationExamineBlackListService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Future;

/**
 * <p>
 * 审核应用学生黑名单 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-05-15
 */
@RestController
@RequestMapping("/rxRegistrationExamine/blackList")
@SecretBody
public class RxRegistrationExamineBlackListController {
    @Resource
    private RxRegistrationExamineBlackListService rxRegistrationExamineBlackListService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;


    @PostMapping("/add")
    @ApiModelProperty("添加学生黑名单")
    public ResponseResult addBlackList(@RequestBody RxRegistrationExamineBlackListReq blackListReq) {
        return rxRegistrationExamineBlackListService.addBlackList(blackListReq);
    }

    @PostMapping("/batchAdd")
    @ApiModelProperty("批量添加学生黑名单")
    public ResponseResult batchAddBlackList(@RequestBody RxRegistrationExamineBlackListBatchAddReq blackListReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        ResponseResult commonCodeEnum;
        try {
            Future<ResponseResult> future = rxRegistrationExamineBlackListService.batchAddBlackList(blackListReq, user_id);
            while (true) {
                if (future.isDone()) {
                    commonCodeEnum = future.get();
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return commonCodeEnum;
    }

    @PostMapping("/delete")
    @ApiModelProperty("删除学生黑名单")
    public ResponseResult deleteBlackList(@RequestBody RxRegistrationExamineBlackListReq blackListReq) {
        return rxRegistrationExamineBlackListService.deleteBlackList(blackListReq);
    }

    @PostMapping("/update")
    @ApiModelProperty("修改学生黑名单")
    public ResponseResult updateBlackList(@RequestBody RxRegistrationExamineBlackListReq blackListReq) {
        return rxRegistrationExamineBlackListService.updateBlackList(blackListReq);
    }

    @GetMapping("/list")
    @ApiModelProperty("获取学生黑名单列表")
    public ResponseResult getBlackList(@RequestParam(value = "searchStr", required = false) String searchStr,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return rxRegistrationExamineBlackListService.getBlackList(searchStr, pageNum, pageSize);
    }

}

